package com.imu.purse.modules.app.dao;

import java.util.List;
import org.apache.ibatis.annotations.Select;
import com.imu.purse.modules.app.entity.ImuUserLoginEntity;
import com.imu.core.base.BaseMapper;

/**
 * 用户登录记录
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-03-21 14:47:08
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface ImuUserLoginMapper extends BaseMapper<ImuUserLoginEntity>
{
	/**
     * 分页查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"user_id, ",
					"app_id, ",
					"os, ",
					"os_ver, ",
					"dev_name, ",
					"dev_code, ",
					"account, ",
					"token, ",
					"time_create",
		    "FROM imu_user_login ",
		    "WHERE status != -1",
			"<when test = 'userId != null'>",
		    	"AND `user_id` = #{userId}",
		    "</when>",
			"<when test = 'appId != null'>",
		    	"AND `app_id` = #{appId}",
		    "</when>",
			"<when test = 'os != null'>",
		    	"AND `os` = #{os}",
		    "</when>",
			"<when test = 'osVer != null'>",
		    	"AND `os_ver` = #{osVer}",
		    "</when>",
			"<when test = 'devName != null'>",
		    	"AND `dev_name` = #{devName}",
		    "</when>",
			"<when test = 'devCode != null'>",
		    	"AND `dev_code` = #{devCode}",
		    "</when>",
			"<when test = 'account != null'>",
		    	"AND `account` = #{account}",
		    "</when>",
			"<when test = 'token != null'>",
		    	"AND `token` = #{token}",
		    "</when>",
			"<when test = 'timeCreate != null'>",
		    	"AND `time_create` = #{timeCreate}",
		    "</when>",
		    "<when test = 'stimeStr != null'>",
		    	"AND cs &gt;= #{stimeStr}",
		    "</when>",
		    "<when test = 'etimeStr != null'>",
				"AND cs &lt;= #{etimeStr}",
			"</when>",
		    "ORDER BY cs DESC",
    	"</script>"
	})
    public List<ImuUserLoginEntity> findByPage(final ImuUserLoginEntity entity);	
	/**
     * 根据token查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"user_id, ",
					"app_id, ",
					"os, ",
					"os_ver, ",
					"dev_name, ",
					"dev_code, ",
					"account, ",
					"token, ",
					"time_create",
		    "FROM imu_user_login ",
		    "WHERE status != -1",
			"<when test = 'userId != null'>",
		    	"AND `user_id` = #{userId}",
		    "</when>",
			"<when test = 'appId != null'>",
		    	"AND `app_id` = #{appId}",
		    "</when>",
			"<when test = 'os != null'>",
		    	"AND `os` = #{os}",
		    "</when>",
			"<when test = 'osVer != null'>",
		    	"AND `os_ver` = #{osVer}",
		    "</when>",
			"<when test = 'devName != null'>",
		    	"AND `dev_name` = #{devName}",
		    "</when>",
			"<when test = 'devCode != null'>",
		    	"AND `dev_code` = #{devCode}",
		    "</when>",
			"<when test = 'account != null'>",
		    	"AND `account` = #{account}",
		    "</when>",
			"<when test = 'token != null'>",
		    	"AND `token` = #{token}",
		    "</when>",
			"<when test = 'timeCreate != null'>",
		    	"AND `time_create` = #{timeCreate}",
		    "</when>",
		    "<when test = 'stimeStr != null'>",
		    	"AND cs &gt;= #{stimeStr}",
		    "</when>",
		    "<when test = 'etimeStr != null'>",
				"AND cs &lt;= #{etimeStr}",
			"</when>",
		    "ORDER BY cs DESC",
    	"</script>"
	})
    public List<ImuUserLoginEntity> selectByToken(final ImuUserLoginEntity entity);	

}
